package com.cks.eduservice.controller;


import com.cks.commonutils.R;
import com.cks.eduservice.entity.EduCourse;
import com.cks.eduservice.entity.vo.CourseInfoVo;
import com.cks.eduservice.entity.vo.CoursePublishVo;
import com.cks.eduservice.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-01-18
 */
@RestController
@RequestMapping("/eduservice/edu-course")
@CrossOrigin
public class EduCourseController {

    @Autowired
    private EduCourseService eduCourseService;

    //添加课程基本信息
    @PostMapping("addCourseInfo")
    public R  addCourseInfo(@RequestBody CourseInfoVo courseInfoVo){

        String id=eduCourseService.addCourseInfo(courseInfoVo);
        return R.ok().data("courseId",id);
    }
    //根据课程id查询课程基本信息
    @GetMapping("getCouresInfo/{couresId}")
    public R  getCouresInfo(@PathVariable String couresId)
    {
       CourseInfoVo courseInfoVo= eduCourseService.getCouresInfo(couresId);
       return R.ok().data("courseInfo",courseInfoVo);
    }
    //修改课程信息
    @PostMapping("updateCoursInfo")
    public  R updateCoursInfo(@RequestBody CourseInfoVo courseInfoVo){

    eduCourseService.updateCourserInfo(courseInfoVo);
        return R.ok();
    }
    //根据课程id查询课程确认信息
    @GetMapping("/getPublishCourInfo/{id}")
    public  R getPublishCourInfo(@PathVariable String id){

        CoursePublishVo CoursePublishVo =eduCourseService.getPublishCourInfo(id);


        return  R.ok().data("CoursePublishVo",CoursePublishVo);
    }
    //改变课程的状态发布
    @GetMapping("/publicCourse/{id}")
    public  R publicCourse(@PathVariable String id){

        EduCourse eduCourse = new EduCourse();
        eduCourse.setId(id);
        eduCourse.setStatus("Normal");  //改变课程状态
        eduCourseService.updateById(eduCourse);
       return  R.ok();
    }
    //得到所有课程信息
    @PostMapping("/getCourselist")
    public R getCourselist(){
        List<EduCourse> list = eduCourseService.list(null);

      return   R.ok().data("list",list);
    }
 //删除课程
    @DeleteMapping("/delCourse/{id}")
    public  R delCourse(@PathVariable String id){
        eduCourseService.removeCourse(id);
        return R.ok();
    }

}

